﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Flashado.Framework;

namespace Dropthings.Widget.Widgets.ComWeather
{

    /// <summary>简单天气预报数据操作(直接从JSON获取)</summary>
    public class WeatherSimple
    {

        private const string __Url = "http://m.weather.com.cn/data/{0}.html";
        public WeatherSimple() { }
        public WeatherSimpleInfo weatherinfo { get; set; }
        /// <summary>获取简单天气预报</summary>
        /// <param name="name">城市代码</param>
        /// <returns>天气预报</returns>
        public static WeatherSimpleInfo Get(string code)
        {
            try
            {
                using (WebClient wc = new WebClient())
                {
                    wc.Encoding = Encoding.UTF8;
                    var url = string.Format(__Url, code);
                    string str = wc.DownloadString(url);
                    return SerializationHelper.JsonDeserialize<WeatherSimple>(str).weatherinfo;
                }
            }
            catch { return null; }
        }
    }
}


